package com.bjpowernode.springboot.controller;

import com.bjpowernode.springboot.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "/user")
public class UserController {

    //用户登录请求
    @RequestMapping(value="/login")
    public @ResponseBody Object login(HttpServletRequest request){
        User user=new User();
        user.setId(1001);
        user.setName("xiaoming");
        request.getSession().setAttribute("myUser",user);

        return "login SUCCESS";
    }

    //该请求需要用户登录之后才可访问
    @RequestMapping(value="/center")
    public @ResponseBody Object center(){
        return "See center message";
    }

    //该请求用户不登陆也可以访问
    @RequestMapping(value="/out")
    public @ResponseBody Object out(){
        return "Out see anytime";
    }

    //如何用户未登录但访问了需要登录才可以访问的请求，之后会跳转至该请求路径
    @RequestMapping(value="/error")
    public @ResponseBody Object error(){
        return "ERROR";
    }
}
